<?php

namespace App\Http\Controllers\Admin\User;

use App\Message;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;

class MessageController extends Controller
{
    //
    public function index($id)
    {
        if (Auth::check()) {
            $authId = Auth::user()->id;
            if ($authId != $id) {
                return "access denied";
            } else {
                $messages = Message::where('to', Auth::user()->name)->orderBy('created_at', 'desc')->get();
                return view('admin/user/message/index')->withMessages($messages);
            }

        } else {
            return redirect('/login');
        }
    }
}
